package com.sunny.l38;

public class Solution {

    private boolean flag = false;

    public boolean hasPathSum(TreeNode root, int sum) {
        dfs(root, sum);
        return flag;
    }

    public void dfs(TreeNode node, int sum){
        if(null == node){
            return;
        }
        if(null == node.left && null == node.right){
            if(sum - node.val == 0){
                flag = true;
            }
        }else{
            if(null != node.left){
                dfs(node.left, sum-node.val);
            }
            if(null != node.right){
                dfs(node.right, sum-node.val);
            }
        }
    }
}

class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;
    TreeNode(int x) { val = x; }
}
